<template>
	<view class="sales_order">
		<view class="team_top">
			<view class="nav">
				<u-tabs :list="navList" height='88' active-color='#26C281' inactive-color='#222222' :is-scroll="false" :current="current" @change="navChange"></u-tabs>
			</view>
		</view>
		<view style="height: 112rpx;"></view>
		<!-- <view style="height: 88rpx;"></view>
		<view class="num_list">
			<view class="txt">
				<text class="t_num">12</text>
				<text class="t_tip">卖单总量</text>
			</view>
			<view class="txt">
				<text class="t_num">12</text>
				<text class="t_tip">卖单总额</text>
			</view>
		</view> -->
		<!--  -->
		<view class="no_html" v-if="list.length==0">
			<image src="@/static/images/no_img5.png" mode=""></image>
			<text>暂无买单信息</text>
		</view>
		<!--  -->
		<view v-else>
			<view class="list" v-for="(item,index) in list" :key="index" @click="detailsBtn(item.id)">
				<view class="list_top">
					<view class="text">{{item.createtime}}</view>
					<view class="text right" v-if="item.status==1">{{item.games==1?'上午仓':'下午仓'}}-预售中</view>
					<view class="text right" v-if="item.status==2">{{item.games==1?'上午仓':'下午仓'}}-已匹配</view>
					<view class="text right" v-if="item.status==3">{{item.games==1?'上午仓':'下午仓'}}-支付凭证已上传</view>
					<view class="text right" v-if="item.status==4">{{item.games==1?'上午仓':'下午仓'}}-已完成-店面审核通过</view>
					<view class="text right" v-if="item.status==5">{{item.games==1?'上午仓':'下午仓'}}-已拒绝-等待店长审核</view>
					<view class="text right" v-if="item.status==6">{{item.games==1?'上午仓':'下午仓'}}-已关闭</view>
				</view>
				<view class="goods_info">
					<image :src="item.goods_image" mode="aspectFill"></image>
					<view class="info">
						<view class="name txt-cut">{{item.goods_name}}</view>
						<view class="num">
							<text class="left">￥{{item.wyy}}</text>
							<text class="right">{{item.pay_money}}件</text>
						</view>
					</view>
				</view>
				<view class="all_money" style="padding-bottom: 30rpx;">
					<text>总价：</text>￥{{item.pay_money}}
				</view>
				<!-- <view class="list_btn">
					<text class="btn1" @click.stop="shoukuanBtn(item)">收款账户</text>
					<text class="btn1" v-if="item.status==3" @click.stop="wanNoBtn(item.id)">拒绝交易</text>
					<text class="btn2" v-if="item.status==3" @click.stop="wanBtn(item.id)">完成交易</text>
				</view> -->
			</view>
			<view class="mall_loading" v-if="list.length">
				<u-loadmore :status="status" color='#999' />
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				navList:[{
					name: '上架中',
					type: 1,
				}, {
					name: '已完成',
					type: 4,
				}, {
					name: '已关闭',
					type: 6,
				}],
				current: 0,
				id:'',
				status: 'loadmore', //加载前值为loadmore，加载中为loading，没有数据为nomore
				page: 1,
				list: [],
				bankInfo:{
					name:'',
					bank:'',
					number:'',
				},
			};
		},
		onLoad(opt) {
			this.id=opt.id
		},
		onShow() {
			this.page = 1
			this.getList()
		},
		methods:{
			// 列表
			getList() {
				var that = this
				if(that.page==1){
					that.$tips.showLoading('加载中')
				}else{
					that.status = 'loading'
				}
				var params = {
					user_id:that.id,
					page:that.page,
					status: that.navList[that.current].type
				}
				that.$httpApi.sellOrderList(params).then((res) => {
					if (res.code == 1) {
						if (that.page == 1) {
							that.list = []
							that.$tips.hideLoading()
						}
						if (res.data.current_page == res.data.last_page) {
							that.status = 'nomore'
						} else {
							that.status = 'loadmore'
						}
						that.list = that.list.concat(res.data.data)
					}
				})
			},
			// nav
			navChange(index){
				this.current=index
				this.page = 1
				this.getList()
			},
			// 收款账号
			shoukuanBtn(item){
				this.bankInfo={
					name:item.username,
					bank:item.openingbank_name,
					number:item.card_number,
				},
				this.$refs.pay_info.openBtn()
			},
			// 详情
			detailsBtn(val){
				uni.navigateTo({
					url:'/pages/shop/sell_out_details?id='+val
				})
			},
			// 拒绝交易
			wanNoBtn(val){
				var that = this
				that.$tips.showLoading('拒绝中')
				var params = {
					order_id:val,
				}
				that.$httpApi.orderNo(params).then((res)=>{
					that.$tips.hideLoading()
					if(res.code==1){
						that.$tips.showToast('拒绝成功')
						that.page = 1
						that.getList()
					}
				})
			},
			// 完成交易
			wanBtn(val){
				var that = this
				that.$tips.showLoading('确认中')
				var params = {
					order_id:val,
				}
				that.$httpApi.goodsOrderOk(params).then((res)=>{
					that.$tips.hideLoading()
					if(res.code==1){
						that.$tips.showToast('交易完成')
						that.page = 1
						that.getList()
					}
				})
			},
		},
		onReachBottom() {
			if (this.status == 'nomore' || this.status == 'loading') {
				return
			}
			this.page++
			this.getList()
		},
	}
</script>

<style lang="less">
	.sales_order{
		width: 100%;
		.team_top{
			position: fixed;
			z-index: 10;
			width: 100%;
			background: #fff;
			border-bottom: 2rpx solid #f7f8fa;
			.nav{
				width: 100%;
				height: 88rpx;
			}
		}
		.num_list{
			width: 100%;
			padding: 24rpx 0;
			background: #fff;
			display: flex;
			justify-content: space-between;
			.txt{
				flex: 1;
				// width: 100%;
				border-left: 2rpx solid #f7f8fa;
				text{
					display: block;
					width: 100%;
					text-align: center;
				}
				.t_num{
					font-size: 32rpx;
					font-family: OPPOSans-Bold, OPPOSans;
					font-weight: bold;
					color: #222222;
				}
				.t_tip{
					padding-top: 8rpx;
					font-size: 24rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #999999;
				}
			}
			.txt:first-child{
				border-left: none;
			}
		}
		.list{
			width: 100%;
			background: #fff;
			margin-bottom: 24rpx;
			.list_top{
				width: 100%;
				line-height: 88rpx;
				padding: 0 32rpx;
				border-bottom: 2rpx solid #f7f8fa;
				display: flex;
				align-items: center;
				justify-content: space-between;
				.text{
					font-size: 28rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #333333;
				}
				.right{
					color: #666;
				}
			}
			.goods_info{
				width: 100%;
				padding: 24rpx 32rpx;
				display: flex;
				image{
					display: block;
					width: 168rpx;
					height: 168rpx;
					border-radius: 10rpx;
				}
				.info{
					width: calc(100% - 168rpx);
					padding-left: 20rpx;
					height: 168rpx;
					.name{
						width: 100%;
						font-size: 32rpx;
						font-family: PingFang SC-Medium, PingFang SC;
						font-weight: 500;
						color: #222222;
					}
					.num{
						width: 100%;
						padding-top: 32rpx;
						display: flex;
						align-items: center;
						justify-content: space-between;
						.left{
							font-size: 28rpx;
							font-family: PingFang SC-Medium, PingFang SC;
							font-weight: 500;
							color: #222222;
						}
						.right{
							font-size: 28rpx;
							font-family: PingFang SC-Regular, PingFang SC;
							font-weight: 400;
							color: #666666;
						}
					}
				}
			}
			.all_money{
				width: 100%;
				padding: 0 32rpx;
				text-align: right;
				font-size: 40rpx;
				font-family: PingFang SC-Bold, PingFang SC;
				font-weight: bold;
				color: #222;
				text{
					font-size: 32rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #222222;
				}
			}
			.list_btn{
				width: 100%;
				padding: 32rpx;
				display: flex;
				justify-content: flex-end;
				text{
					margin-left: 12rpx;
					display: block;
					padding: 0 20rpx;
					height: 64rpx;
					line-height: 60rpx;
					border-radius: 32rpx;
					font-size: 28rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
				}
				.btn1{
					color: #999;
					border: 2rpx solid #EBEBEB;
				}
				.btn2{
					color: #26C281;
					border: 2rpx solid #26C281;
				}
			}
		}
	}
</style>
